package com.itheima;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * map集合嵌套List集合
 */
public class HashMapPractice {
    public static void main(String[] args) {
        // 创建一个List集合，用来存储城市
        List<String> cities = new ArrayList<>();
        //创建一个map集合，用来存储省份和城市
        Map<String,List<String>> map = new HashMap<>();
        cities.add("成都");
        cities.add("绵阳");
        cities.add("德阳");
        cities.add("广元");
        cities.add("乐山");
        cities.add("内江");
        cities.add("南充");
        cities.add("宜宾");
        cities.add("广安");
        map.put("四川",cities);

        List<String> cities1 = new ArrayList<>();
        cities1.add("长沙");
        cities1.add("常德");
        cities1.add("岳阳");
        cities1.add("益阳");
        cities1.add("株洲");
        map.put("湖南",cities1);
        //遍历
        printMap(map);

    }
    public static void printMap(Map<String,List<String> > map){
        map.forEach((k,v)->{
            StringBuffer sb = new StringBuffer();
            //将v转换成特定的字符串
            v.forEach(city->{
                sb.append(city+",");
            });
            //最后把sb最后的逗号去掉
            sb.deleteCharAt(sb.length()-1);
            //将v转换成String
            String result = k+"="+sb;
            System.out.println(result);
        });
    }

}
